package com.mythesis.bpel.ui.client;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mythesis.bpel.ui.client.controls.BpelControl;

public class BpelItemsGroup extends VerticalPanel {
	private final PickupDragController dragController;
	
	public BpelItemsGroup(PickupDragController dragController){
		this.dragController = dragController;
	}
	
	public void add(BpelControl w) {
	    dragController.makeDraggable(w);
	    super.add(w);
	}

	@Override
	public boolean remove(Widget w) {
		// TODO Auto-generated method stub
		int index = getWidgetIndex(w);
	    if (index != -1 && w instanceof BpelControl) {
	    	BpelControl clone = ((BpelControl) w).cloneControl();
	      dragController.makeDraggable(clone);
	      insert(clone, index);
	    }
	    return super.remove(w);
	}	
	
}
